<%--
  Created by IntelliJ IDEA.
  User: 陈春宇
  Date: 2023/12/12
  Time: 13:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="/human-resource/css/bootstrap.min.css">
    <script src="/human-resource/js/bootstrap.min.js"></script>
    <script src="/human-resource/js/jquery-3.6.0.min.js"></script>
    <title>人力资源管理系统首页</title>
    <style>
    </style>
</head>
<body>


<!-- 导航条 -->
<section class="navbar navbar-expand-lg navbar-brand bg-body">
    <nav class="container">
        <div class="navbar-collapse collapse" id="nav-menu">
            <ul class="navbar-nav">
                <li class="nav-item">
                    <a class="nav-link active"><%=session.getAttribute("username")%></a>
                </li>
                <li class="nav-item">
                    <button class="nav-link" id="logout">退出登录</button>
                </li>
            </ul>
        </div>

    </nav>
</section>

<!--表格-->
<div class="container mt-5">

    <div class="col-md-10 offset-md-1">

        <div class="row">
            <!-- 新增按钮 -->
            <div class="col-8">
                <button type="button" class="btn btn-primary rounded-0" data-bs-toggle="modal" data-bs-target="#addModal">
                    新增
                </button>
            </div>
            <!-- 搜索按钮 -->
            <div class="col-4">
                <form action="/human-resource/score/selectKey">
                    <div class="input-group mb-3">
                        <input type="text" class="form-control rounded-0" placeholder="请输入员工姓名" name="keywords" value="<c:if test="${keywords != null}">${keywords}</c:if>">
                        <button class="btn btn-secondary rounded-0" type="submit" id="search">搜索</button>
                    </div>
                </form>
            </div>

        </div>

        <!-- 信息表单 -->
        <table class="table mt-3">
            <thead>
            <tr>
                <th scope="col">ID</th>
                <th scope="col">姓名</th>
                <th scope="col">工资</th>
                <th scope="col">部门</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${messageList}" var="message">
                <tr>
                    <td>${message.major}</td>
                    <td>${message.clazz}</td>
                    <td>${message.sname}</td>
                    <td>${message.score}</td>
                    <td>
                        <button type="button" class="btn btn-warning btn-sm rounded-0" data-bs-toggle="modal" data-bs-target="#updateModal" onclick="update(1)">修改</button>
                        <button type="button" class="btn btn-outline-danger btn-sm rounded-0" data-bs-toggle="modal" data-bs-target="#deleteModal" onclick="del(1)">删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>



<!-- 新增按钮表单弹窗 -->
<div class="modal fade" id="addModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">新增成员</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"
                        aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="col-md-10 offset-md-1">
                    <section class="px-1">
                        <form action="">
                            <div class="input-group input-group-lg p-3">
                                <label for="MID" class="col-sm-3 col-form-label"><b>ID</b></label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="MID" name="MID">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="mname" class="col-sm-3 col-form-label"><b>姓名</b></label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="mname" name="mname">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="salary" class="col-sm-3 col-form-label"><b>工资</b></label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="salary" name="salary">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="branch" class="col-sm-3 col-form-label"><b>部门</b></label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="branch" name="branch">
                                </div>
                            </div>
                            <div class="p-3 mb-3">
                                <button class="btn btn-danger d-block w-100 rounded-0" type="submit">提交</button>
                            </div>

                        </form>

                    </section>
                </div>
            </div>

        </div>
    </div>
</div>

<!-- 修改按钮表单弹窗 -->
<div class="modal fade" id="updateModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">修改信息</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="col-md-10 offset-md-1">
                    <section class="px-1">
                        <form action="">
                            <div class="input-group input-group-lg p-3">
                                <label for="uMID" class="col-sm-3 col-form-label"><b>ID</b></label>
                                <div class="col-sm-9">
                                    <input type="number" class="form-control" id="uMID" name="MID">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="umname" class="col-sm-3 col-form-label"><b>姓名</b></label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="umname" name="mname">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="usalary" class="col-sm-3 col-form-label"><b>工资</b></label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="usalary" name="salary">
                                </div>
                            </div>
                            <div class="input-group input-group-lg p-3">
                                <label for="ubranch" class="col-sm-3 col-form-label"><b>部门</b></label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="ubranch" name="branch">
                                </div>
                            </div>
                            <div class="p-3 mb-3">
                                <button class="btn btn-danger d-block w-100 rounded-0" type="submit">提交</button>
                            </div>

                        </form>

                    </section>
                </div>
            </div>

        </div>
    </div>
</div>

<!-- 删除按钮表单弹窗 -->
<div class="modal fade" id="deleteModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">消息提示</h5>
            </div>
            <form action="">
                <div class="modal-body">
                    <div hidden>
                        <input type="text" readonly id="delStuId" name="sid">
                    </div>
                    您确定删除该条数据吗?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-sm btn-danger" data-bs-dismiss="modal">删除</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!--操作弹窗消息-->
<c:if test="${alertMsg!=null}">
    <div class="toast show text-bg-primary bottom-0 end-0 position-fixed rounded-0">
        <div class="d-flex">
            <div class="toast-body">
                    ${alertMsg}
            </div>
            <button type="button" class="btn-close btn-close-white m-auto me-2" data-bs-dismiss="toast"></button>
        </div>
    </div>
</c:if>



</body>

<script>

    document.querySelector("#logout").addEventListener('click', function (){
        $.ajax({
            type: 'get',
            url: '/human-resource/user/logout',
            success: function (data){
                location.href='/human-resource/login.jsp'
            }
        })
    })

    function update(id){
        document.getElementById("updateStuId").setAttribute("value", id);
    }

    function del(id){
        document.getElementById("delStuId").setAttribute("value", id);
    }

</script>

</html>


